<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author ThinkGem
-->
<template>
  <PageWrapper :sidebarWidth="500">
    <template #sidebar>
      <!-- <BasicTree
        :title="t('机构')"
        :search="true"
        :toolbar="true"
        :showIcon="true"
        :api="officeTreeData"
        :defaultExpandLevel="2"
        @select="handleSelect"
      /> -->
      <BasicTable @register="registerTable" @row-click="handleRowClick">
        <!-- 表格标题 -->
        <template #tableTitle>
          <Icon :icon="getTitle.icon" class="m-1 pr-1" />
          <span> {{ getTitle.value }} </span>
        </template>

        <template #ccode="{ record }">
          (<DictLabel
            :dictType="'M8_order_level'"
            :dictValue="record.order.jjlevel"
            :defaultValue="'0'"
          />)
          <span> {{ record.order.ccode }} </span>
        </template>
      </BasicTable>
    </template>
    <ListView :orderId="orderId" :taskStatus_in="'0,1,2,9'" />
  </PageWrapper>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsTestIndex',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, ref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { PageWrapper } from '/@/components/Page';
  // import { BasicTree } from '/@/components/Tree';
  // import { officeTreeData } from '/@/api/sys/office';
  import ListView from './list.vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  // import { testDataDelete } from '/@/api/test/testData';
  // import { testDataDisable, testDataEnable } from '/@/api/test/testData';
  // import { officeTreeData } from '/@/api/sys/office';
  // import { areaTreeData } from '/@/api/sys/area';
  import { FormProps } from '/@/components/Form';

  import { orderTaskListData } from '/@/api/m8/machine/task';
  import { DictLabel } from '/@/components/Dict';

  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: '订单任务列表',
  };

  const { t } = useI18n('m8.task');
  const { showMessage } = useMessage();
  const orderId = ref<string>('');

  // function handleSelect(keys: string[]) {
  //   orderId.value = keys[0];
  // }

  //配置表单内容
  const searchForm: FormProps = {
    baseColProps: { lg: 12, md: 8 },
    labelWidth: 90,
    showAdvancedButton: true,
    alwaysShowLines: 3,
    schemas: [
      {
        label: t('订单号'),
        field: 'order.ccode',
        component: 'Input',
      },
      {
        label: t('加工单位'),
        field: 'order.jgdw',
        component: 'Input',
      },
      {
        label: t('开始'),
        field: 'beginDate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
        ifShow: false,
      },
      {
        label: t('截止'),
        field: 'endDate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
        ifShow: false,
      },
      {
        label: t('计划开始'),
        field: 'planBeginDate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
        ifShow: false,
      },
      {
        label: t('计划截止'),
        field: 'planEndDate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
        ifShow: false,
      },
      {
        label: t('完工'),
        field: 'overDate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
        ifShow: false,
      },

      {
        label: t('状态'),
        field: 'flowStatus_in',
        component: 'CheckboxGroup',
        defaultValue: '0,1,9',
        componentProps: {
          dictType: 'm8_order_status',
        },
        colProps: { lg: 24, md: 8 },
      },

      {
        label: t('订单ID'),
        field: 'order.id',
        component: 'Input',
        ifShow: false,
      },
    ],
  };
  //配置表格表头菜单
  const tableColumns: BasicColumn[] = [
    {
      title: t('订单号'),
      dataIndex: 'order.ccode',
      key: 'orders.ccode',
      sorter: true,
      width: 160,
      align: 'left',
      slot: 'ccode',
    },
    {
      title: t('加工单位'),
      dataIndex: 'order.jgdw',
      key: 'orders.jgdw',
      sorter: true,
      width: 100,
      align: 'left',
      // slot: 'firstColumn',
    },

    // {
    //   title: t('加工名称'),
    //   dataIndex: 'order.jgname',
    //   key: 'orders.jgname',
    //   sorter: true,
    //   width: 100,
    //   align: 'left',
    //   // dictType: 'sys_menu_type',
    // },
    // {
    //   title: t('订单数量'),
    //   dataIndex: 'order.iqty',
    //   key: 'orders.iqty',
    //   sorter: true,
    //   width: 80,
    //   align: 'left',
    // },
  ];
  const [registerTable, { reload }] = useTable({
    api: orderTaskListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns, //配置表格内容数组对象
    // actionColumn: actionColumn, //配置表格右边操作按钮
    formConfig: searchForm, //配置表单内容
    // showTableSetting: true, //表格右上角3个默认按钮
    useSearchForm: true, //表单是否展示
    canResize: true, //表格是否flex布局
    rowKey: 'order',
    showIndexColumn: false,
    rowSelection: {
      type: 'radio',
    },
  });

  function handleRowClick(record: Recordable) {
    orderId.value = record.order.id;
    console.log(orderId.value);

    // record.onEdit?.(true, false);
    // reload2({
    //   searchInfo: { 'route.id': record.id },
    // });
  }

  // async function handleDisable(record: Recordable) {
  //   const res = await testDataDisable(record);
  //   showMessage(res.message);
  //   handleSuccess();
  // }

  // async function handleEnable(record: Recordable) {
  //   const res = await testDataEnable(record);
  //   showMessage(res.message);
  //   handleSuccess();
  // }

  // async function handleDelete(record: Recordable) {
  //   const res = await testDataDelete(record);
  //   showMessage(res.message);
  //   handleSuccess();
  // }

  function handleSuccess() {
    reload();
  }
</script>
